﻿using System.Windows.Media;
using CuteRibs.MVVMLib;
using CuteRibs.WowArmory.Models;
using CuteRibs.WowArmory.Resources;
using System.Windows;

namespace CuteRibs.WowArmory.ViewModels
{
	public class RealmViewModel : ViewModelBase
	{
		private Visibility isMarked;

		public Visibility IsMarked
		{
			get { return this.isMarked; }
			set
			{
				if (this.isMarked != value)
				{
					this.isMarked = value;
					this.NotifyPropertyChanged("IsMarked");
				}
			}
		}

		public Realm Realm { get; set; }
		public string Icon { get; set; }
		public string Name { get; set; }
		public string Type { get; set; }
		public SolidColorBrush TypeColor { get; set; }
		public string Population { get; set; }
		public SolidColorBrush PopulationColor { get; set; }

		public RealmViewModel(Realm realm, bool isMarked = false)
		{
			this.IsMarked = isMarked ? Visibility.Visible : Visibility.Collapsed;
			this.Realm = realm;
			this.Name = realm.Name;
			this.Type = realm.Type;
			this.Population = AppRes.ResourceManager.GetString("Population_" + realm.Population.Replace("/", string.Empty).ToUpper());

			if (realm.Queue)
			{
				this.Icon = "/Resources/Images/queue.png";
			}
			else if (realm.Status)
			{
				this.Icon = "/Resources/Images/up.png";
			}
			else
			{
				this.Icon = "/Resources/Images/down.png";
			}

			string color;

			switch (realm.Type)
			{
				case "rp":
					color = "Color_LimeGreen";
					break;
				case "pvp":
					color = "Color_FireBrick";
					break;
				default:
					color = "Color_Tan";
					break;
			}

			this.TypeColor = App.Current.Resources[color] as SolidColorBrush;

			switch (realm.Population)
			{
				case "full":
				case "high":
					color = "Color_FireBrick";
					break;
				case "low":
					color = "Color_LimeGreen";
					break;
				case "new":
					color = "Color_DodgerBlue";
					break;
				case "medium":
				case "n/a":
				default:
					color = "Color_Tan";
					break;
			}

			this.PopulationColor = App.Current.Resources[color] as SolidColorBrush;
		}

		public void SetMarked()
		{
			this.IsMarked = Visibility.Visible;
		}
	}
}
